﻿using HalconDotNet;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using Halcon二次开发.Model.工具区域的扩展类;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;
using static System.Windows.Forms.LinkLabel;

namespace Halcon二次开发.Tools
{
    public class UtiyHalcon
    {
        /// <summary>
        /// 平移矩阵加旋转矩阵
        /// </summary>
        /// <param name="region">初始区域</param>
        /// <param name="current_row">当前模板行坐标</param>
        /// <param name="current_column">当前模板列坐标</param>
        /// <param name="current_phi">当前模板角度</param>
        /// <param name="firstModel_row">第一个模板行坐标</param>
        /// <param name="firstModel_column">第一个模板列坐标</param>
        /// <param name="firstModel_phi">第一个模板角度</param>
        /// <returns></returns>
        public static HObject MatrixCalculate(HObject region, double current_row, double current_column, double current_phi, double firstModel_row, double firstModel_column, double firstModel_phi)
        {
            //创建平移矩阵
            HOperatorSet.HomMat2dIdentity(out HTuple hv_HomMat2DIdentity);
            HOperatorSet.HomMat2dTranslate(hv_HomMat2DIdentity, current_row - firstModel_row, current_column - firstModel_column, out HTuple hv_HomMat2DTranslate);
            HOperatorSet.AffineTransRegion(region, out HObject ho_RegionLineTranslated, hv_HomMat2DTranslate,
"constant");

            //创建旋转矩阵
            HOperatorSet.HomMat2dIdentity(out HTuple hv_HomMat2DIdentity2);
            HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity2, current_phi - firstModel_phi, current_row, current_column,
                out HTuple hv_HomMat2DRotate);
            HOperatorSet.AffineTransRegion(ho_RegionLineTranslated, out HObject ho_RegionAffineTrans,
                hv_HomMat2DRotate, "nearest_neighbor");//最终线段hobject  ho_RegionAffineTrans
            return ho_RegionAffineTrans;
        }
    }
}
